import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/login_after.vue"),
    meta: { isokpath: true },
  }, //登录页面
  {
    path: "/index", component: () => import("../views/index.vue"), meta: { isokpath: false }, children:
      [
        { path: "home", component: () => import("@/views/home.vue") },//首页 
        { path: "/", redirect: "home" },//首页 

        /**
         * 监控管理
         */
        { path: 'loginLog', component: () => import("@/views/hj/login_log.vue") },//登入日志
        /**
         * 系统管理
         */
        { path: 'user', component: () => import("@/views/hj/user_management.vue") },//用户管理
        { path: 'role', component: () => import("@/views/hj/role_management.vue") },//角色管理
        { path: 'menu', component: () => import("@/views/hj/menu_management.vue") },//菜单管理
        { path: 'sysstation', component: () => import("@/views/lc/sys/sysstation.vue") },//岗位管理
        { path: 'organization', component: () => import("@/views/hj/organization_management.vue") },//组织管理
        { path: 'personalinformation', component: () => import("@/views/lc/sys/personalinformation.vue") },//个人信息
        { path: 'loginLog', component: () => import("@/views/hj/login_log.vue") },
        { path: 'TruckManage', component: () => import("@/views/lzh/TruckManage.vue") }, //车俩管理
        { path: 'FleetManage', component: () => import("@/views/lzh/FleetManage.vue") }, //车队管理
        { path: 'TransportLineType', component: () => import("@/views/lzh/TransportLineType.vue") },// 线路类型管理
        { path: 'TruckDetails', component: () => import("@/views/lzh/TruckDetails.vue") },// 车俩管理详情
        { path: 'TransportLine', component: () => import("@/views/lzh/TransportLine.vue") },// 线路管理TransportLine
        { path: 'TruckDriver', component: () => import("@/views/lzh/TruckDriver.vue") },// 司机管理
        { path: 'TruckDriverDetails', component: () => import("@/views/lzh/TruckDriverDetails.vue") },// 司机管理详情
        { path: "tasktransport", component: () => import("@/views/lc/transport/tasktransport.vue") },//运输任务管理
        { path: "tasktransportdetails", component: () => import("@/views/lc/transport/tasktransportDetails.vue") },//运输任务副页面
        { path: "driverOrderxiangq", component: () => import("@/views/lc/transport/driverOrderDetail.vue") },//运单详情页面
        { path: "driverjob", component: () => import("@/views/lc/driverjob/driverjob.vue") },//司机作业单管理
        { path: "Institutionaldataview", component: () => import("@/views/lc/Institutionaldataview/Institutionaldataview.vue") },//机构数据看板
        { path: "jg", component: () => import("@/views/yh/jg.vue") },//机构作业范围
        { path: "order", component: () => import("@/views/yh/order.vue") },//用户订单
        { path: "orderDetail", component: () => import("@/views/yh/orderDetail.vue") },//订单详情
        { path: "driverOrder", component: () => import("@/views/yh/driverOrder.vue") },//司机订单
        { path: "driverOrderDetail", component: () => import("@/views/yh/driverOrderDetail.vue") },//司机订单详情
        { path: "courierOrder", component: () => import("@/views/yh/courierOrder.vue") },//快递员订单
        { path: "courierScop", component: () => import("@/views/yh/courierScop.vue") },//快递员作业范围
        { path: "goodsType", component: () => import("@/views/yh/goodsType.vue") },//快递员作业范围
        { path: "TruckType", component: () => import("@/views/lzh/TruckType.vue") },//车型管理
        { path: "courierScopDetail", component: () => import("@/views/yh/courierScopDetail.vue") },//快递员范围
        
      ]
    },
]


const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach((to, from, next) => {
  //用户如果已经登陆，放行
  //用户需要登录，应该放行
  // 路由中有 isokpath属性，表示因该放行的路由(url)
  if (to.matched.some((val) => val.meta.isokpath == true)) {
    next();
  } else {
    if (sessionStorage.getItem("satoken")) {
      next();
    } else {
      next({ path: "/" });
    }
  }
});

export default router;
